package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.album.service.VodService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.atguigu.tingshu.vo.album.TrackUpdateFileVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

    @Autowired
    private TrackInfoService trackInfoService;
    @Resource
    VodService vodService;

    // http://127.0.0.1:8500/api/album/trackInfo/uploadTrack
    @Operation(summary = "上传音频")
    @PostMapping("uploadTrack")
    public Result<TrackUpdateFileVo> uploadTrack(MultipartFile file) {
        TrackUpdateFileVo updateFileVo = this.vodService.uploadTrack(file);
        return Result.ok(updateFileVo);
    }

    //http://127.0.0.1:8500/api/album/trackInfo/saveTrackInfo
    @GuiGuLogin
    @Operation(summary = "新增创作音频")
    @PostMapping("saveTrackInfo")
    public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo) {
        this.trackInfoService.saveTrackInfo(trackInfoVo);
        return Result.ok();
    }

    // http://127.0.0.1:8500/api/album/trackInfo/findUserTrackPage/1/10
    @GuiGuLogin
    @Operation(summary = "声音专辑分页列表")
    @PostMapping("findUserTrackPage/{page}/{limit}")
    public Result<Page<TrackListVo>> findUserTrackPage(@PathVariable Integer page,
                                                       @PathVariable Integer limit,
                                                       @RequestBody TrackInfoQuery query) {
        Page<TrackListVo> trackInfoVoPage = this.trackInfoService.findUserTrackPage(page, limit, query);
        return Result.ok(trackInfoVoPage);

    }

    //http://127.0.0.1:8500/api/album/trackInfo/removeTrackInfo/51943
    @GuiGuLogin
    @Operation(summary = "声音删除")
    @DeleteMapping("removeTrackInfo/{trackId}")
    public Result removeTrackInfo(@PathVariable Long trackId) {
        this.trackInfoService.removeTrackInfo(trackId);
        return Result.ok();

    }


    // http://127.0.0.1:8500/api/album/trackInfo/getTrackInfo/51943
    @Operation(summary = "声音查询")
    @GetMapping("getTrackInfo/{trackId}")
    public Result<TrackInfo> getTrackInfo(@PathVariable Long trackId) {
        TrackInfo trackInfo = this.trackInfoService.getById(trackId);
        return Result.ok(trackInfo);
    }

    //http://127.0.0.1:8500/api/album/trackInfo/updateTrackInfo/51933
    @GuiGuLogin
    @Operation(summary = "声音更新保存")
    @PutMapping("updateTrackInfo/{trackId}")
    public Result updateTrackInfo(@PathVariable Long trackId, @RequestBody TrackInfoVo trackInfoVo) {

        this.trackInfoService.updateTrackInfo(trackId, trackInfoVo);
        return Result.ok();

    }
}

